﻿Imports System.Windows.Forms
Imports Microsoft.Win32

Public Class ResourceManager
    Private M_Tab As TabControl
    Private M_PluginPath As String
    Private M_MacroPath As String
    Private M_ProjectPath As String
    Private M_DataPath As String
    Private M_Settings As String
    Private M_PluginSet As String
    Private M_Develop As Boolean = False
    Private M_ScanPlugin As Boolean = True
    Private m_AppPath As String
    Public Event DevelopmentModeChanged(ByVal NewState As Boolean)
    Public Property AppPath() As String
        Get
            Return m_AppPath
        End Get
        Set(ByVal value As String)
            m_AppPath = value
        End Set
    End Property
    Public Property ScanPluginFolder() As Boolean
        Get
            Return M_ScanPlugin
        End Get
        Set(ByVal value As Boolean)
            M_ScanPlugin = value
        End Set
    End Property
    Public Property MainTab() As TabControl
        Get
            Return M_Tab
        End Get
        Set(ByVal value As TabControl)
            M_Tab = value
        End Set
    End Property
    Public Property SettingsPath() As String
        Get
            Return M_Settings
        End Get
        Set(ByVal value As String)
            M_Settings = value
        End Set
    End Property
    Public Property DataPath() As String
        Get
            Return M_DataPath
        End Get
        Set(ByVal value As String)
            M_DataPath = value
        End Set
    End Property
    Public Property PluginPath() As String
        Get
            Return M_PluginPath
        End Get
        Set(ByVal value As String)
            M_PluginPath = value
        End Set
    End Property
    Public Property MacroPath() As String
        Get
            Return M_MacroPath
        End Get
        Set(ByVal value As String)
            M_MacroPath = value
        End Set
    End Property
    Public Property ProjectPath() As String
        Get
            Return M_ProjectPath
        End Get
        Set(ByVal value As String)
            M_ProjectPath = value
        End Set
    End Property
    Public Property PluginSet() As String
        Get
            Return M_PluginSet
        End Get
        Set(ByVal value As String)
            M_PluginSet = value
        End Set
    End Property
    Public Property DevelopmentMode() As Boolean
        Get
            Return M_Develop
        End Get
        Set(ByVal value As Boolean)
            M_Develop = value
            RaiseEvent DevelopmentModeChanged(value)
        End Set
    End Property

    Public Sub SaveSettings(ByVal Path As String)
        Dim FS As New System.IO.FileStream(IO.Path.Combine(Path, "UniSet.ini"), IO.FileMode.Create)
        Dim Writer As New IO.StreamWriter(FS)
        Writer.WriteLine(M_PluginPath)
        Writer.WriteLine(M_MacroPath)
        Writer.WriteLine(M_ProjectPath)
        Writer.WriteLine(M_DataPath)
        Writer.WriteLine(M_Settings)
        Writer.WriteLine(M_PluginSet)
        Writer.WriteLine(M_Develop)
        Writer.Close()
    End Sub
    Public Function LoadSettings(ByVal Path As String) As Boolean
        Dim exists As Boolean = False
        If IO.File.Exists(IO.Path.Combine(Path, "UniSet.ini")) Then
            Dim FS As New System.IO.FileStream(IO.Path.Combine(Path, "UniSet.ini"), IO.FileMode.Open)
            Dim reader As New IO.StreamReader(FS)
            M_PluginPath = reader.ReadLine
            M_MacroPath = reader.ReadLine
            M_ProjectPath = reader.ReadLine
            M_DataPath = reader.ReadLine
            M_Settings = reader.ReadLine
            M_PluginSet = reader.ReadLine
            If reader.ReadLine.Contains("True") Then
                M_Develop = True
                RaiseEvent DevelopmentModeChanged(True)
            Else
                M_Develop = False
                RaiseEvent DevelopmentModeChanged(False)
            End If
            reader.Close()
            Return True
        Else
            Return False
        End If
    End Function
End Class
